package com.example.room_type.service.impl;


import com.example.model.room_type.PriceRule;
import com.example.model.room_type.RoomType;
import com.example.room_type.mapper.PriceRuleMapper;
import com.example.room_type.mapper.RoomTypeMapper;
import com.example.room_type.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoomTypeServiceImpl implements RoomTypeService {

    @Autowired
    private PriceRuleMapper priceRuleMapper;

    @Autowired
    private RoomTypeMapper roomTypeMapper;

    @Override
    public RoomType get(Long id) {
        return roomTypeMapper.get(id);
    }

    @Override
    public List<RoomType> list(RoomType roomType) {
        return roomTypeMapper.list(roomType);
    }

    @Transactional
    @Override
    public int insert(RoomType roomType) {
        PriceRule priceRule = roomType.getPriceRule();
        int insert = roomTypeMapper.insert(roomType);
        priceRule.setRoomTypeId(roomType.getRoomTypeId());
        priceRuleMapper.insert(priceRule);
        return insert;
    }

    @Override
    public int update(RoomType roomType) {
        return roomTypeMapper.update(roomType);
    }

    @Override
    public int delete(Long id) {
        return roomTypeMapper.delete(id);
    }


}
